import requests
import random
from .userAgent import *

def get_headers():
    user_agent = random.choice (user_agents)
    headers = {
        "User-Agent": user_agent}
    return headers



def request_content(url):
    try:
        headers = get_headers()
        proxies = get_proxy()
        response = requests.get(url,headers=headers,proxies=proxies)
        response.raise_for_status()
        response.encoding = response.apparent_encoding
        content = response.text
    except Exception as e:
        print(e,end='')
    return content

def get_proxy():
    return random.choice(proxy_list)

proxy_list = []
with open("./ip.txt",'r') as f:
    lines = f.readlines()
    for line in lines:
        s = line.split(' ')
        proxy = {s[0]:s[1].strip()}
        proxy_list.append(proxy)
